package com.example.newproject_overseas.components


import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.newproject_overseas.R
import com.example.newproject_overseas.Screen.Main.Square
import com.example.newproject_overseas.model.entity.Order

@Composable
fun OrderItems(order:Order) {

    Column() {

        Column(modifier = Modifier
            .padding(top = 15.dp)
            .padding(horizontal = 15.dp)
            .fillMaxWidth()
            .height(235.dp)
            .background(Color(0xFFFFFFFF))
            .padding(10.dp)) {

            Row {
                Image(
                    painter = painterResource(id = R.drawable.idcardback),
                    contentDescription = null,
                    modifier = Modifier
                        .width(80.dp)
                        .height(50.dp)
                        .scale(0.9f)
                        .offset(x = (-10).dp))
                Text(
                    text = order.name,
                    fontSize = 20.sp,
                    modifier = Modifier.padding(top = 10.dp)
                )
                Spacer(modifier = Modifier.weight(1f))
                Box(modifier = Modifier.padding(top = 5.dp)){
                    Square()
                    Image(
                        painter = painterResource(id = R.drawable.telinfo),
                        contentDescription = null,
                        modifier = Modifier
                            .padding(top = 5.dp, start = 5.dp)
                            .width(25.dp)
                            .height(25.dp)
                            .scale(0.9f)

                    )
                }

            }

            Column(modifier = Modifier
                .padding(top = 10.dp)
                .height(170.dp)
                .fillMaxWidth()
                .background(Color(0xFFF1F1F1))
                .padding(vertical = 20.dp, horizontal = 10.dp)) {
                Row() {
                    Text(
                        text = "Loananmount:",
                        color = Color(0xFF999999)
                    )
                    Spacer(modifier = Modifier.weight(1f))
                    Text(text = "₹ ")
                    Text(text = order.money.toString())
                }

                Spacer(modifier = Modifier
                    .height(10.dp)
                )

                Row() {
                    Text(
                        text = "Loan Period(Days):",
                        color = Color(0xFF999999)
                    )
                    Spacer(modifier = Modifier
                        .weight(1f)

                    )
                    Text(text = order.days)
                }

                Spacer(modifier = Modifier
                    .height(10.dp)
                )

                Row() {
                    Text(
                        text = "Loan date:",
                        color = Color(0xFF999999)
                    )
                    Spacer(modifier = Modifier.weight(1f))
                    Text(text = order.date)
                }

                Spacer(modifier = Modifier
                    .height(10.dp)
                )
                Row() {
                    Text(
                        text = "Loan notenumber:",
                        color = Color(0xFF999999)
                    )
                    Spacer(modifier = Modifier.weight(1f))
                    Text(text = order.notenumber)
                }
            }
        }

        Row(
            modifier = Modifier
                .padding(horizontal = 13.dp)
                .background(if (order.state == 0) Color(0xFF009919) else Color(0xFFDA2525))
                .height(50.dp)
                .fillMaxWidth(),
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.Center ) {
            Text(
                text = if(order.state == 0) "SUCCESS" else "Fail",
                color = Color(0xFFFFFFFF),
                fontSize = 20.sp,
                fontWeight = FontWeight.Normal
            )

        }
    }
}

@Preview
@Composable
fun OrderItemsPreview() {
    OrderItems(Order("1","Loan notenumber01",15.00,"7DAY","2023-02-0708:59:22","L20230207062922806",0))
}

